package com.cloud.drore.eboss.operation.mapper;

import com.cloud.drore.eboos.common.base.MyMapper;

import com.cloud.drore.eboos.common.entity.dealer.MerchantVo;

import com.cloud.drore.eboss.operation.entity.Merchant;
import com.cloud.drore.eboss.operation.entity.po.MerchantPo;
import com.cloud.drore.eboss.operation.entity.vo.MerchantOperationVo;
import com.cloud.drore.eboss.operation.mapper.provider.MerchantProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos MERCHANT_AUDIT_CANCEL<br>
 * @CreateDate: Created in 2018/1/6 0006 下午 1:11 <br>
 * @Author: <a href="410508961@qq.com">夏凯</a>
 */

@Repository
public interface MerchantMapper extends MyMapper<Merchant> {
    String deleteMerchantSql = "update eboos_merchant set merchant_state = 'MERCHANT_AUDIT_CANCEL' where id = ${key}";
    String backMerchantSql = "update eboos_merchant set merchant_state = 'MERCHANT_AUDIT_ALREADY' where id = ${key}";

    //查询商户id、名称用于关联商户的添加
    @Select("select id,merchant_name from eboos_merchant")
    List<Merchant> queryMerchantList();

    //修改商户基本信息
    @UpdateProvider(type = MerchantProvider.class, method = "updateSql")
    int updateMerchantStateSql(Merchant merchant);

    //删除商户信息
    @Update(deleteMerchantSql)
    int deleteMerchantSql(@Param("key") Object key);

    @Update(backMerchantSql)
    int backMerchantSql(@Param("key") Object key);

    @Select("select * from eboos_merchant where merchant_type = 'MERCHANT_SUPPLIER' and is_deleted=0")
    List<Merchant> query();

    @Select("select id,merchant_name from eboos_merchant where merchant_type = 'MERCHANT_SUPPLIER'")
    List<MerchantVo> getSupplierListDictionary();

    @Select("select id,merchant_name from eboos_merchant where merchant_type = 'MERCHANT_DISTRIBUTE'")
    List<MerchantVo> getDealerListDictionary();

    @Select("select * from eboos_merchant where merchant_type = 'MERCHANT_DISTRIBUTE'")
    List<Merchant> queryDistributor();

    //根据商户id添加商户编号的信息
    @Update("update eboos_merchant set merchant_num='${merchantNum}' where id=${id}")
    int updateMerchantNum(@Param("id") Long id, @Param("merchantNum") String merchantNum);

    // 根据商户名称查询当前商户是否存在，防止商户名称重复
    @Select("select id from eboos_merchant where merchant_name='${merchantName}' and  merchant_state!='MERCHANT_AUDIT_CANCEL'")
    List<Merchant> findMerchantList(@Param("merchantName") String merchantName);

    //根据商户类型和商户名称查询所有商户列表新
    @SelectProvider(type = MerchantProvider.class, method = "queryMerchantInitList")
    List<MerchantOperationVo> queryMerchantInitList(MerchantPo merchant);

    //根据商户id查询merchant_industry
    @Select("select merchant_industry from eboos_merchant where id=${id}")
    String queryMerchantIndustry(@Param("id") Long id);
    //根据商户id查询merchant_industry
    @Select("select merchant_type,merchant_industry from eboos_merchant where id=${id}")
    Merchant queryMerchantForManager(@Param("id") Long id);
    //根据商户的id查询商户的名称
    @Select("select merchant_name from eboos_merchant where id=${id}")
    Merchant queryMerchantNameById(@Param("id") Long id);
    //根据id查询商户的类型
    @Select("select merchant_type from eboos_merchant where id=${id}")
    Merchant queryMerchantType(@Param("id") Long id);
    //根据供应商的名称获得编号和性质
    @Select("select merchant_num,merchant_industry from eboos_merchant where merchant_name='${name}'")
    Merchant queryMerchantByName(@Param("name") String name);
}
